8299593: getprotobyname should not be used

Reviewed-by: cjplummer
This commit is contained in:
Daniel Jeliński 2023-01-09 07:32:55 +00:00
parent c4449224bb
commit d03a5d9580
2 changed files with 4 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -189,11 +189,9 @@ int
dbgsysSetSocketOption(int fd, jint cmd, jboolean on, jvalue value)
{
if (cmd == TCP_NODELAY) {
struct protoent *proto = getprotobyname("TCP");
int tcp_level = (proto == 0 ? IPPROTO_TCP: proto->p_proto);
uint32_t onl = (uint32_t)on;
if (setsockopt(fd, tcp_level, TCP_NODELAY,
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
(char *)&onl, sizeof(uint32_t)) < 0) {
return SYS_ERR;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -268,11 +268,9 @@ int
dbgsysSetSocketOption(int fd, jint cmd, jboolean on, jvalue value)
{
if (cmd == TCP_NODELAY) {
struct protoent *proto = getprotobyname("TCP");
int tcp_level = (proto == 0 ? IPPROTO_TCP: proto->p_proto);
long onl = (long)on;
if (setsockopt(fd, tcp_level, TCP_NODELAY,
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
(char *)&onl, sizeof(long)) < 0) {
return SYS_ERR;
}