Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: liweinan/recipies
base: 6eda8fdb18
...
head fork: liweinan/recipies
compare: b591565dc5
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 33 additions and 0 deletions.
  1. +6 −0 c/Makefile
  2. +18 −0 c/gethostbyaddr.c
  3. +9 −0 c/hostname.c
6 c/Makefile
View
@@ -38,6 +38,12 @@ play_stdarg: stdarg.o
null.o: null.c
cc null.c -o null.o
+hostname.o: hostname.c
+ cc hostname.c -o hostname.o
+
+gethostbyaddr: gethostbyaddr.c
+ cc $< -o $@
+
clean:
rm *.o
rm *.tmp
18 c/gethostbyaddr.c
View
@@ -0,0 +1,18 @@
+#include <arpa/inet.h>
+#include <err.h>
+#include <netdb.h>
+#include <stdio.h>
+
+int main() {
+ const char *ipstr = "127.0.0.1";
+ struct in_addr ip;
+ struct hostent *hp;
+
+ if (!inet_aton(ipstr, &ip))
+ errx(1, "can't parse IP address %s", ipstr);
+
+ if ((hp = gethostbyaddr((const void *)&ip, sizeof ip, AF_INET)) == NULL)
+ errx(1, "no name associated with %s", ipstr);
+
+ printf("name associated with %s is %s\n", ipstr, hp->h_name);
+}
9 c/hostname.c
View
@@ -0,0 +1,9 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ char* hn = malloc(sizeof(char) * 100);
+ gethostname(hn, sizeof(char) * 100);
+ printf("hostname: %s\n", hn);
+}

No commit comments for this range

Something went wrong with that request. Please try again.