Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * knock.c
- * Make a knock packet
- * By J. Stuart McMurray
- * Created 20160317
- * Last Modified 20160317
- */
- #include "plainshell.h"
- int make_knock(const char *address, const char *port) {
- unsigned char a[4];
- uint16_t p;
- int ret;
- /* Convert the address */
- if (0 == (ret = inet_pton(AF_INET, address, (void*)a))) {
- errx(1, "invalid address");
- } else if (-1 == ret) {
- err(2, "address parse error");
- }
- /* Convert the port */
- if (1 != sscanf(port, "%hu", &p)) {
- err(3, "port parse error");
- }
- p = htons(p);
- /* Write the bytes to stdout */
- if (-1 == write(STDOUT_FILENO, a, sizeof(a))) {
- err(4, "write");
- }
- if (-1 == write(STDOUT_FILENO, &p, sizeof(p))) {
- err(5, "write");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement