static int create_socket(struct netsocket_config *config) { struct addrinfo hints = { 0 }; int err; log_info("Getting address info of %s#%s...", config->mcast_addr, config->mcast_port); hints.ai_socktype = SOCK_DGRAM; err = getaddrinfo(config->mcast_addr, config->mcast_port, &hints, &addr_candidates); if (err) { log_err("getaddrinfo() failed: %s", gai_strerror(err)); return err; } bound_address = addr_candidates; while (bound_address) { log_info("Trying an address candidate..."); err = try_address(config); if (!err) return 0; bound_address = bound_address->ai_next; } log_err("None of the candidates yielded a valid socket."); freeaddrinfo(addr_candidates); return 1; }
/* * Description: Whenever we initiate a transaction, the first byte clocked * onto the bus after the start condition is the address (7 bit) of the * device we want to talk to. This function manipulates the address specified * so that it makes sense to the hardware when written to the IIC peripheral. * * Note: 10 bit addresses are not supported in this driver, although they are * supported by the hardware. This functionality needs to be implemented. */ static inline int iic_doAddress(struct i2c_adapter *adap, struct i2c_msg *msg, int retries) { struct iic_regs *iic; unsigned short flags = msg->flags; unsigned char addr; iic = (struct iic_regs *) IIC_DEV(vaddr); /* * The following segment for 10 bit addresses needs to be ported */ #if 0 /* Ten bit addresses not supported right now */ if ((flags & I2C_M_TEN)) { /* a ten bit address */ addr = 0xf0 | ((msg->addr >> 7) & 0x03); DEB2(printk(KERN_DEBUG "addr0: %d\n", addr)); /* try extended address code... */ ret = try_address(adap, addr, retries); if (ret != 1) { printk(KERN_ERR "iic_doAddress: died at extended address code.\n"); return -EREMOTEIO; } /* the remaining 8 bit address */ iic_outb(msg->addr & 0x7f); /* Status check comes here */ if (ret != 1) { printk(KERN_ERR "iic_doAddress: died at 2nd address code.\n"); return -EREMOTEIO; } if (flags & I2C_M_RD) { i2c_repstart(adap); /* okay, now switch into reading mode */ addr |= 0x01; ret = try_address(adap, addr, retries); if (ret != 1) { printk(KERN_ERR "iic_doAddress: died at extended address code.\n"); return -EREMOTEIO; } } } else
// try to broadcast the message to a node by first // checking if there is a known and responsive internalhost // for this hostname, then the same for a known externalhost // and then if those fail try to connect using the hostname // as the address. So first time connecting with // $ daust remote 192.168.50.3 // will result in directly connecting to that node by ip address char *broadcast_to_remote(char *rmt, char *buf, char *uq) { char *r = NULL; char *d = NULL; d = internalhost_by_hostname(rmt, head); r = try_internal(d, buf, uq); if (r == NULL) { d = externalhost_by_hostname(rmt, head); r = try_external(d, buf, uq); } if (r == NULL) { r = try_address(rmt, buf, uq); } return r; }