Skip to content

Instantly share code, notes, and snippets.

View xuesongbj's full-sized avatar
🦀
Rust

xuesong xuesongbj

🦀
Rust
View GitHub Profile
@xuesongbj
xuesongbj / How to compare an IPv6 is greater or less than in C
Created May 15, 2019 01:51
How to compare an IPv6 is greater or less than in C?
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
const char *ip6str = "2a03:6300:1:103:211:5bff:fe31:13e1";
const char *first = "2a03:6300:1:103:218:5bff:fe31:13e1";
const char *last = "2a03:6300:1:103:220:5bff:fe31:13e1";
@xuesongbj
xuesongbj / inet_ntop and inet_pton example
Created May 15, 2019 09:03
inet_ntop and inet_pton example
// IPv6 demo of inet_ntop() and inet_pton()
// (basically the same except with a bunch of 6s thrown around)
struct sockaddr_in6 sa;
char str[INET6_ADDRSTRLEN];
// store this IP address in sa:
inet_pton(AF_INET6, "2001:db8:8714:3a90::12", &(sa.sin6_addr));
// now get it back and print it