Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8299593: getprotobyname should not be used
Reviewed-by: cjplummer
  • Loading branch information
djelinski committed Jan 9, 2023
1 parent c444922 commit d03a5d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/jdk.jdwp.agent/unix/native/libdt_socket/socket_md.c
@@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 2 additions & 4 deletions src/jdk.jdwp.agent/windows/native/libdt_socket/socket_md.c
@@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

1 comment on commit d03a5d9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.