Browse Source

[core] sock_addr_set_port()

master
Glenn Strauss 11 months ago
parent
commit
f7018e3d39
  1. 20
      src/sock_addr.c
  2. 2
      src/sock_addr.h

20
src/sock_addr.c

@ -191,6 +191,26 @@ int sock_addr_is_addr_eq_bits(const sock_addr *a, const sock_addr *b, int bits)
}
void sock_addr_set_port (sock_addr * const restrict saddr, const unsigned short port)
{
switch (saddr->plain.sa_family) {
case AF_INET:
saddr->ipv4.sin_port = htons(port);
break;
#ifdef HAVE_IPV6
case AF_INET6:
saddr->ipv6.sin6_port = htons(port);
break;
#endif
#ifdef HAVE_SYS_UN_H
/*case AF_UNIX:*/
#endif
default:
break;
}
}
int sock_addr_assign (sock_addr * const restrict saddr, int family, unsigned short nport, const void * const restrict naddr)
{
switch (family) {

2
src/sock_addr.h

@ -50,6 +50,8 @@ int sock_addr_is_addr_port_eq (const sock_addr *saddr1, const sock_addr *saddr2)
__attribute_pure__
int sock_addr_is_addr_eq_bits(const sock_addr * restrict a, const sock_addr * restrict b, int bits);
void sock_addr_set_port (sock_addr * restrict saddr, unsigned short port);
int sock_addr_assign (sock_addr * restrict saddr, int family, unsigned short nport, const void * restrict naddr);
int sock_addr_inet_pton(sock_addr * restrict saddr, const char * restrict str, int family, unsigned short port);

Loading…
Cancel
Save