mirror of
https://github.com/nmap/nmap.git
synced 2026-11-22 07:30:59 +00:00
Some checks are pending
nmap multiplatform autobuilds / build (arm64, gcc, ubuntu-latest-gcc-arm64, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, freebsd-15-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, macos-15-clang, macos-15) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, macos-26-clang, macos-26) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, netbsd-10-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, openbsd-7-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, solaris-11-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (clang, ubuntu-latest-clang, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (egcc, openbsd-7-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (gcc, freebsd-15-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (gcc, netbsd-10-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (gcc, solaris-11-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (gcc, ubuntu-latest-gcc, ubuntu-latest) (push) Waiting to run
nmap multiplatform autobuilds / build (msvc, windows-latest-msvc, windows-latest) (push) Waiting to run
75 lines
1.3 KiB
C
75 lines
1.3 KiB
C
/*
|
|
* ip-win32.c
|
|
*
|
|
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
|
|
*
|
|
* $Id$
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "dnet.h"
|
|
|
|
struct ip_handle {
|
|
WSADATA wsdata;
|
|
SOCKET fd;
|
|
struct sockaddr_in sin;
|
|
};
|
|
|
|
ip_t *
|
|
ip_open(void)
|
|
{
|
|
BOOL on;
|
|
ip_t *ip;
|
|
|
|
if ((ip = calloc(1, sizeof(*ip))) != NULL) {
|
|
if (WSAStartup(MAKEWORD(2, 2), &ip->wsdata) != 0) {
|
|
free(ip);
|
|
return (NULL);
|
|
}
|
|
if ((ip->fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) ==
|
|
INVALID_SOCKET)
|
|
return (ip_close(ip));
|
|
|
|
on = TRUE;
|
|
if (setsockopt(ip->fd, IPPROTO_IP, IP_HDRINCL,
|
|
(const char *)&on, sizeof(on)) == SOCKET_ERROR) {
|
|
SetLastError(ERROR_NETWORK_ACCESS_DENIED);
|
|
return (ip_close(ip));
|
|
}
|
|
ip->sin.sin_family = AF_INET;
|
|
ip->sin.sin_port = htons(666);
|
|
}
|
|
return (ip);
|
|
}
|
|
|
|
ssize_t
|
|
ip_send(ip_t *ip, const void *buf, size_t len)
|
|
{
|
|
struct ip_hdr *hdr = (struct ip_hdr *)buf;
|
|
|
|
ip->sin.sin_addr.s_addr = hdr->ip_src;
|
|
|
|
if ((len = sendto(ip->fd, (const char *)buf, len, 0,
|
|
(struct sockaddr *)&ip->sin, sizeof(ip->sin))) != SOCKET_ERROR)
|
|
return (len);
|
|
|
|
return (-1);
|
|
}
|
|
|
|
ip_t *
|
|
ip_close(ip_t *ip)
|
|
{
|
|
if (ip != NULL) {
|
|
WSACleanup();
|
|
if (ip->fd != INVALID_SOCKET)
|
|
closesocket(ip->fd);
|
|
free(ip);
|
|
}
|
|
return (NULL);
|
|
}
|