/*!
 *  @file    main.c
 *  @author  Kang IkSeon (ikseon1026@gmail.com)
 *
 *  @internal
 *       Created:  2018년 01월 30일
 *     Copyright:  Copyright (c) 2018, Kang IkSeon
 */

#include <stdio.h>
#include <stdint.h>

#include "src/lib.h"

int main() {
//  int n, len;
//  unsigned char packet[PACKET_LEN];
//  char dmac[] = {0x08, 0x62, 0x66, 0x7c, 0xed, 0x6c};
//
//  printf ("ether size : %zu\n", sizeof(struct ether_header));
//
//  make_ether_packet(packet, dmac);
//  make_wol_packet(packet + sizeof(struct ether_header), dmac);
//
//  send_wol("enp0s25", packet, PACKET_LEN);
	int sock;
  int port = 9;
	struct sockaddr_in target_addr;
  unsigned char packet[WOL_LEN];
  char dmac[] = {0x08, 0x62, 0x66, 0x7c, 0xed, 0x6c};
  const char *ip = "183.98.140.67";
  // const char *ip = "183.98.140.154";

	if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
		perror("socket ");
		return 1;
	}

	memset(&target_addr, 0x00, sizeof(target_addr));
	target_addr.sin_family = AF_INET;
	target_addr.sin_addr.s_addr = inet_addr(ip);
	target_addr.sin_port = htons(port);

  make_wol_packet(packet, dmac);

	sendto(sock, packet, WOL_LEN, 0,
		(struct sockaddr *)&target_addr, sizeof(target_addr));

	close(sock);

	return 0;
}
