2
* low-level ip_address ugliness
3
* Copyright (C) 2000 Henry Spencer.
5
* This library is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU Library General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or (at your
8
* option) any later version. See <http://www.fsf.org/copyleft/lgpl.txt>.
10
* This library is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13
* License for more details.
15
* RCSID $Id: portof.c,v 1.6 2004/04/09 18:00:36 mcr Exp $
21
- portof - get the port field of an ip_address
23
int /* network order */
25
const ip_address *src;
27
switch (src->u.v4.sin_family) {
29
return src->u.v4.sin_port;
32
return src->u.v6.sin6_port;
35
return -1; /* "can't happen" */
41
- setportof - set the port field of an ip_address
45
int port; /* network order */
48
switch (dst->u.v4.sin_family) {
50
dst->u.v4.sin_port = port;
53
dst->u.v6.sin6_port = port;
59
- sockaddrof - get a pointer to the sockaddr hiding inside an ip_address
65
switch (src->u.v4.sin_family) {
67
return (struct sockaddr *)&src->u.v4;
70
return (struct sockaddr *)&src->u.v6;
73
return NULL; /* "can't happen" */
79
- sockaddrlenof - get length of the sockaddr hiding inside an ip_address
81
size_t /* 0 for error */
83
const ip_address *src;
85
switch (src->u.v4.sin_family) {
87
return sizeof(src->u.v4);
90
return sizeof(src->u.v6);