diff options
| author | bcook <> | 2016-07-01 00:29:14 +0000 |
|---|---|---|
| committer | bcook <> | 2016-07-01 00:29:14 +0000 |
| commit | ceb780fa1d91285e88945a25b91f2eb689ce1116 (patch) | |
| tree | 9b7bba91b12f7f07a71f3d06468dce0385304dc9 /src | |
| parent | feaba99148498e3901e21567eef6244222c71431 (diff) | |
| download | openbsd-ceb780fa1d91285e88945a25b91f2eb689ce1116.tar.gz openbsd-ceb780fa1d91285e88945a25b91f2eb689ce1116.tar.bz2 openbsd-ceb780fa1d91285e88945a25b91f2eb689ce1116.zip | |
Simplify IP proto-specific sockopt error handling.
This makes error messages more specific and simplifies
masking compatible sections for the portable version.
ok beck@
Diffstat (limited to '')
| -rw-r--r-- | src/usr.bin/nc/netcat.c | 60 |
1 files changed, 26 insertions, 34 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index cc5d58f25e..83cd59a738 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: netcat.c,v 1.156 2016/06/28 17:35:14 jca Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.157 2016/07/01 00:29:14 bcook Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
| 4 | * Copyright (c) 2015 Bob Beck. All rights reserved. | 4 | * Copyright (c) 2015 Bob Beck. All rights reserved. |
| @@ -1412,18 +1412,13 @@ set_common_sockopts(int s, int af) | |||
| 1412 | err(1, NULL); | 1412 | err(1, NULL); |
| 1413 | } | 1413 | } |
| 1414 | if (Tflag != -1) { | 1414 | if (Tflag != -1) { |
| 1415 | int proto, option; | 1415 | if (af == AF_INET && setsockopt(s, IPPROTO_IP, |
| 1416 | 1416 | IP_TOS, &Tflag, sizeof(Tflag)) == -1) | |
| 1417 | if (af == AF_INET6) { | ||
| 1418 | proto = IPPROTO_IPV6; | ||
| 1419 | option = IPV6_TCLASS; | ||
| 1420 | } else { | ||
| 1421 | proto = IPPROTO_IP; | ||
| 1422 | option = IP_TOS; | ||
| 1423 | } | ||
| 1424 | |||
| 1425 | if (setsockopt(s, proto, option, &Tflag, sizeof(Tflag)) == -1) | ||
| 1426 | err(1, "set IP ToS"); | 1417 | err(1, "set IP ToS"); |
| 1418 | |||
| 1419 | else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6, | ||
| 1420 | IPV6_TCLASS, &Tflag, sizeof(Tflag)) == -1) | ||
| 1421 | err(1, "set IPv6 traffic class"); | ||
| 1427 | } | 1422 | } |
| 1428 | if (Iflag) { | 1423 | if (Iflag) { |
| 1429 | if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, | 1424 | if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, |
| @@ -1435,28 +1430,25 @@ set_common_sockopts(int s, int af) | |||
| 1435 | &Oflag, sizeof(Oflag)) == -1) | 1430 | &Oflag, sizeof(Oflag)) == -1) |
| 1436 | err(1, "set TCP send buffer size"); | 1431 | err(1, "set TCP send buffer size"); |
| 1437 | } | 1432 | } |
| 1438 | if (ttl != -1 || minttl != -1) { | 1433 | |
| 1439 | int proto, in_ttl_opt, out_ttl_opt; | 1434 | if (ttl != -1) { |
| 1440 | switch (af) { | 1435 | if (af == AF_INET && setsockopt(s, IPPROTO_IP, |
| 1441 | case AF_INET: | 1436 | IP_TTL, &ttl, sizeof(ttl))) |
| 1442 | proto = IPPROTO_IP; | 1437 | err(1, "set IP TTL"); |
| 1443 | in_ttl_opt = IP_MINTTL; | 1438 | |
| 1444 | out_ttl_opt = IP_TTL; | 1439 | else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6, |
| 1445 | break; | 1440 | IPV6_UNICAST_HOPS, &ttl, sizeof(ttl))) |
| 1446 | case AF_INET6: | 1441 | err(1, "set IPv6 unicast hops"); |
| 1447 | proto = IPPROTO_IPV6; | 1442 | } |
| 1448 | in_ttl_opt = IPV6_MINHOPCOUNT; | 1443 | |
| 1449 | out_ttl_opt = IPV6_UNICAST_HOPS; | 1444 | if (minttl != -1) { |
| 1450 | break; | 1445 | if (af == AF_INET && setsockopt(s, IPPROTO_IP, |
| 1451 | default: | 1446 | IP_MINTTL, &minttl, sizeof(minttl))) |
| 1452 | errx(1, "unknown address family: %d", af); | 1447 | err(1, "set IP min TTL"); |
| 1453 | } | 1448 | |
| 1454 | if (minttl != -1 && setsockopt(s, proto, in_ttl_opt, | 1449 | else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6, |
| 1455 | &minttl, sizeof(minttl))) | 1450 | IPV6_MINHOPCOUNT, &minttl, sizeof(minttl))) |
| 1456 | err(1, "setsockopt minttl"); | 1451 | err(1, "set IPv6 min hop count"); |
| 1457 | if (ttl != -1 && setsockopt(s, proto, out_ttl_opt, | ||
| 1458 | &ttl, sizeof(ttl))) | ||
| 1459 | err(1, "setsockopt ttl"); | ||
| 1460 | } | 1452 | } |
| 1461 | } | 1453 | } |
| 1462 | 1454 | ||
