mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
Properly convert port numbers to/from network byte order
* src/util/network.c: Add htons and ntohs in virSocket(Get|Set)Port
This commit is contained in:
parent
3811eaaa63
commit
91b009cde4
@ -173,6 +173,8 @@ virSocketSetPort(virSocketAddrPtr addr, int port) {
|
||||
if (addr == NULL)
|
||||
return -1;
|
||||
|
||||
port = htons(port);
|
||||
|
||||
if(addr->stor.ss_family == AF_INET) {
|
||||
addr->inet4.sin_port = port;
|
||||
}
|
||||
@ -201,11 +203,11 @@ virSocketGetPort(virSocketAddrPtr addr) {
|
||||
return -1;
|
||||
|
||||
if(addr->stor.ss_family == AF_INET) {
|
||||
return addr->inet4.sin_port;
|
||||
return ntohs(addr->inet4.sin_port);
|
||||
}
|
||||
|
||||
else if(addr->stor.ss_family == AF_INET6) {
|
||||
return addr->inet6.sin6_port;
|
||||
return ntohs(addr->inet6.sin6_port);
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user