-
-/* Convert the host ID string to a MAC address.
- * The string may be a:
- * Host name
- * IP address string
- * MAC address string
-*/
-static inline void get_dest_addr(const char *hostid, struct ether_addr *eaddr)
-{
- struct ether_addr *eap;
-
- eap = ether_aton(hostid);
- if (eap) {
- *eaddr = *eap;
- bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eaddr));
-#if !defined(__UCLIBC__)
- } else if (ether_hostton(hostid, eaddr) == 0) {
- bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr));
-#else
-# warning Need to implement ether_hostton() for uClibc
-#endif
- } else
- bb_show_usage();
-}
-
-static inline int get_fill(unsigned char *pkt, struct ether_addr *eaddr, int broadcast)
-{
- int offset, i;
- unsigned char *station_addr = eaddr->ether_addr_octet;
-
- if (broadcast)
- memset(pkt+0, 0xff, 6);
- else
- memcpy(pkt, station_addr, 6);
- memcpy(pkt+6, station_addr, 6);
- pkt[12] = 0x08; /* Or 0x0806 for ARP, 0x8035 for RARP */
- pkt[13] = 0x42;
- offset = 14;
-
- memset(pkt+offset, 0xff, 6);
- offset += 6;
-
- for (i = 0; i < 16; ++i) {
- memcpy(pkt+offset, station_addr, 6);
- offset += 6;
- }
-
- return offset;
-}
-
-static inline int get_wol_pw(const char *ethoptarg, unsigned char *wol_passwd)
-{
- int passwd[6];
- int byte_cnt, i;
-
- /* handle MAC format */
- byte_cnt = sscanf(ethoptarg, "%2x:%2x:%2x:%2x:%2x:%2x",
- &passwd[0], &passwd[1], &passwd[2],
- &passwd[3], &passwd[4], &passwd[5]);
- /* handle IP format */
- if (byte_cnt < 4)
- byte_cnt = sscanf(ethoptarg, "%d.%d.%d.%d",
- &passwd[0], &passwd[1], &passwd[2], &passwd[3]);
- if (byte_cnt < 4) {
- bb_error_msg("cannot read Wake-On-LAN pass");
- return 0;
- }
-
- for (i = 0; i < byte_cnt; ++i)
- wol_passwd[i] = passwd[i];
-
- bb_debug_msg("password: %2.2x %2.2x %2.2x %2.2x (%d)\n\n",
- wol_passwd[0], wol_passwd[1], wol_passwd[2], wol_passwd[3],
- byte_cnt);
-
- return byte_cnt;
-}