svn commit: r252946 - stable/9/lib/libc/net
Michael Tuexen
tuexen at FreeBSD.org
Sun Jul 7 13:10:32 UTC 2013
Author: tuexen
Date: Sun Jul 7 13:10:31 2013
New Revision: 252946
URL: http://svnweb.freebsd.org/changeset/base/252946
Log:
MFC r243302:
Cleanup the code a bit, which improves the portability.
Modified:
stable/9/lib/libc/net/sctp_sys_calls.c
Directory Properties:
stable/9/lib/ (props changed)
stable/9/lib/libc/ (props changed)
Modified: stable/9/lib/libc/net/sctp_sys_calls.c
==============================================================================
--- stable/9/lib/libc/net/sctp_sys_calls.c Sun Jul 7 13:09:17 2013 (r252945)
+++ stable/9/lib/libc/net/sctp_sys_calls.c Sun Jul 7 13:10:31 2013 (r252946)
@@ -188,15 +188,18 @@ sctp_connectx(int sd, const struct socka
cpto = ((caddr_t)buf + sizeof(int));
/* validate all the addresses and get the size */
for (i = 0; i < addrcnt; i++) {
- if (at->sa_family == AF_INET) {
+ switch (at->sa_family) {
+ case AF_INET:
if (at->sa_len != sizeof(struct sockaddr_in)) {
errno = EINVAL;
return (-1);
}
- memcpy(cpto, at, at->sa_len);
- cpto = ((caddr_t)cpto + at->sa_len);
- len += at->sa_len;
- } else if (at->sa_family == AF_INET6) {
+ memcpy(cpto, at, sizeof(struct sockaddr_in));
+ cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in));
+ len += sizeof(struct sockaddr_in);
+ at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in));
+ break;
+ case AF_INET6:
if (at->sa_len != sizeof(struct sockaddr_in6)) {
errno = EINVAL;
return (-1);
@@ -206,11 +209,13 @@ sctp_connectx(int sd, const struct socka
cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in));
len += sizeof(struct sockaddr_in);
} else {
- memcpy(cpto, at, at->sa_len);
- cpto = ((caddr_t)cpto + at->sa_len);
- len += at->sa_len;
+ memcpy(cpto, at, sizeof(struct sockaddr_in6));
+ cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in6));
+ len += sizeof(struct sockaddr_in6);
}
- } else {
+ at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in6));
+ break;
+ default:
errno = EINVAL;
return (-1);
}
@@ -219,7 +224,6 @@ sctp_connectx(int sd, const struct socka
errno = E2BIG;
return (-1);
}
- at = (struct sockaddr *)((caddr_t)at + at->sa_len);
cnt++;
}
/* do we have any? */
@@ -260,56 +264,57 @@ sctp_bindx(int sd, struct sockaddr *addr
errno = EINVAL;
return (-1);
}
- argsz = (sizeof(struct sockaddr_storage) +
- sizeof(struct sctp_getaddresses));
- gaddrs = (struct sctp_getaddresses *)calloc(1, argsz);
- if (gaddrs == NULL) {
- errno = ENOMEM;
- return (-1);
- }
/* First pre-screen the addresses */
sa = addrs;
for (i = 0; i < addrcnt; i++) {
- if (sa->sa_family == AF_INET) {
- if (sa->sa_len != sizeof(struct sockaddr_in))
- goto out_error;
+ switch (sa->sa_family) {
+ case AF_INET:
+ if (sa->sa_len != sizeof(struct sockaddr_in)) {
+ errno = EINVAL;
+ return (-1);
+ }
sin = (struct sockaddr_in *)sa;
if (sin->sin_port) {
/* non-zero port, check or save */
if (sport) {
/* Check against our port */
if (sport != sin->sin_port) {
- goto out_error;
+ errno = EINVAL;
+ return (-1);
}
} else {
/* save off the port */
sport = sin->sin_port;
}
}
- } else if (sa->sa_family == AF_INET6) {
- if (sa->sa_len != sizeof(struct sockaddr_in6))
- goto out_error;
+ break;
+ case AF_INET6:
+ if (sa->sa_len != sizeof(struct sockaddr_in6)) {
+ errno = EINVAL;
+ return (-1);
+ }
sin6 = (struct sockaddr_in6 *)sa;
if (sin6->sin6_port) {
/* non-zero port, check or save */
if (sport) {
/* Check against our port */
if (sport != sin6->sin6_port) {
- goto out_error;
+ errno = EINVAL;
+ return (-1);
}
} else {
/* save off the port */
sport = sin6->sin6_port;
}
}
- } else {
- /* invalid address family specified */
- goto out_error;
+ break;
+ default:
+ /* Invalid address family specified. */
+ errno = EINVAL;
+ return (-1);
}
-
sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
}
- sa = addrs;
/*
* Now if there was a port mentioned, assure that the first address
* has that port to make sure it fails or succeeds correctly.
@@ -318,20 +323,14 @@ sctp_bindx(int sd, struct sockaddr *addr
sin = (struct sockaddr_in *)sa;
sin->sin_port = sport;
}
+ argsz = sizeof(struct sctp_getaddresses) +
+ sizeof(struct sockaddr_storage);
+ if ((gaddrs = (struct sctp_getaddresses *)malloc(argsz)) == NULL) {
+ errno = ENOMEM;
+ return (-1);
+ }
+ sa = addrs;
for (i = 0; i < addrcnt; i++) {
- if (sa->sa_family == AF_INET) {
- if (sa->sa_len != sizeof(struct sockaddr_in))
- goto out_error;
- } else if (sa->sa_family == AF_INET6) {
- if (sa->sa_len != sizeof(struct sockaddr_in6))
- goto out_error;
- } else {
- /* invalid address family specified */
- out_error:
- free(gaddrs);
- errno = EINVAL;
- return (-1);
- }
memset(gaddrs, 0, argsz);
gaddrs->sget_assoc_id = 0;
memcpy(gaddrs->addr, sa, sa->sa_len);
More information about the svn-src-stable-9
mailing list