Skip to content

Improve hostname functions#872

Merged
matthiasblaesing merged 1 commit intojava-native-access:masterfrom
matthiasblaesing:hostname_utils
Nov 10, 2017
Merged

Improve hostname functions#872
matthiasblaesing merged 1 commit intojava-native-access:masterfrom
matthiasblaesing:hostname_utils

Conversation

@matthiasblaesing
Copy link
Copy Markdown
Member

Fix wrong mapping of libc function gethostname, sethostname,
getdomainname and setdomainname. The functions are defined as:

   int getdomainname(char *name, size_t len);
   int setdomainname(const char *name, size_t len);

   int gethostname(char *name, size_t len);
   int sethostname(const char *name, size_t len);

and a C char[] maps by default to a byte[] in java.

In addition bind the winsock gethostname function:

com.sun.jna.platform.win32.Winsock2.gethostname(byte[], int)

This closes #871

int gethostname(char[] name, int len);
int sethostname(char[] name, int len);
int gethostname(byte[] name, int len);
int sethostname(byte[] name, int len);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should use String.

int getdomainname(char[] name, int len);
int setdomainname(char[] name, int len);
int getdomainname(byte[] name, int len);
int setdomainname(byte[] name, int len);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should use String.

@matthiasblaesing matthiasblaesing force-pushed the hostname_utils branch 2 times, most recently from 7ef9429 to c82b819 Compare November 9, 2017 19:37
Fix wrong mapping of libc function gethostname, sethostname,
getdomainname  and setdomainname. The functions are defined as:

       int getdomainname(char *name, size_t len);
       int setdomainname(const char *name, size_t len);

       int gethostname(char *name, size_t len);
       int sethostname(const char *name, size_t len);

and a C char[] maps by default to a byte[] in java.

In addition bind the winsock gethostname function:

com.sun.jna.platform.win32.Winsock2.gethostname(byte[], int)

The sethostname and setdomainname were tested manually,
as changing the hostname is a privileged operation and
is not regularly possible in unittests.

This closes java-native-access#871
@matthiasblaesing
Copy link
Copy Markdown
Member Author

Thanks for the hint Timothy, adjusted.

@matthiasblaesing matthiasblaesing merged commit fc89e2c into java-native-access:master Nov 10, 2017
@matthiasblaesing matthiasblaesing deleted the hostname_utils branch November 18, 2017 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve hostname utilities

2 participants