Rev 4731 | Rev 4743 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4731 | Rev 4738 | ||
---|---|---|---|
Line 59... | Line 59... | ||
59 | if( addrlen < sizeof( struct sockaddr )) return EINVAL; |
59 | if( addrlen < sizeof( struct sockaddr )) return EINVAL; |
60 | switch( addr->sa_family ){ |
60 | switch( addr->sa_family ){ |
61 | case AF_INET: |
61 | case AF_INET: |
62 | if( addrlen != sizeof( struct sockaddr_in )) return EINVAL; |
62 | if( addrlen != sizeof( struct sockaddr_in )) return EINVAL; |
63 | address_in = ( struct sockaddr_in * ) addr; |
63 | address_in = ( struct sockaddr_in * ) addr; |
64 | * port = address_in->sin_port; |
64 | * port = ntohs( address_in->sin_port ); |
65 | break; |
65 | break; |
66 | case AF_INET6: |
66 | case AF_INET6: |
67 | if( addrlen != sizeof( struct sockaddr_in6 )) return EINVAL; |
67 | if( addrlen != sizeof( struct sockaddr_in6 )) return EINVAL; |
68 | address_in6 = ( struct sockaddr_in6 * ) addr; |
68 | address_in6 = ( struct sockaddr_in6 * ) addr; |
69 | * port = address_in6->sin6_port; |
69 | * port = ntohs( address_in6->sin6_port ); |
70 | break; |
70 | break; |
71 | default: |
71 | default: |
72 | return EAFNOSUPPORT; |
72 | return EAFNOSUPPORT; |
73 | } |
73 | } |
74 | return EOK; |
74 | return EOK; |
75 | } |
75 | } |
76 | 76 | ||
77 | - | ||
78 | int tl_set_address_port( struct sockaddr * addr, int addrlen, uint16_t port ){ |
77 | int tl_set_address_port( struct sockaddr * addr, int addrlen, uint16_t port ){ |
79 | struct sockaddr_in * address_in; |
78 | struct sockaddr_in * address_in; |
80 | struct sockaddr_in6 * address_in6; |
79 | struct sockaddr_in6 * address_in6; |
81 | size_t length; |
80 | size_t length; |
82 | 81 | ||
Line 85... | Line 84... | ||
85 | if( length < sizeof( struct sockaddr )) return EINVAL; |
84 | if( length < sizeof( struct sockaddr )) return EINVAL; |
86 | switch( addr->sa_family ){ |
85 | switch( addr->sa_family ){ |
87 | case AF_INET: |
86 | case AF_INET: |
88 | if( length != sizeof( struct sockaddr_in )) return EINVAL; |
87 | if( length != sizeof( struct sockaddr_in )) return EINVAL; |
89 | address_in = ( struct sockaddr_in * ) addr; |
88 | address_in = ( struct sockaddr_in * ) addr; |
90 | address_in->sin_port = port; |
89 | address_in->sin_port = htons( port ); |
91 | return EOK; |
90 | return EOK; |
92 | case AF_INET6: |
91 | case AF_INET6: |
93 | if( length != sizeof( struct sockaddr_in6 )) return EINVAL; |
92 | if( length != sizeof( struct sockaddr_in6 )) return EINVAL; |
94 | address_in6 = ( struct sockaddr_in6 * ) addr; |
93 | address_in6 = ( struct sockaddr_in6 * ) addr; |
95 | address_in6->sin6_port = port; |
94 | address_in6->sin6_port = htons( port ); |
96 | return EOK; |
95 | return EOK; |
97 | default: |
96 | default: |
98 | return EAFNOSUPPORT; |
97 | return EAFNOSUPPORT; |
99 | } |
98 | } |
100 | } |
99 | } |