當前位置: 首頁>>代碼示例>>C++>>正文


C++ Address_print函數代碼示例

本文整理匯總了C++中Address_print函數的典型用法代碼示例。如果您正苦於以下問題:C++ Address_print函數的具體用法?C++ Address_print怎麽用?C++ Address_print使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Address_print函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: Database_create

void Database_create(struct Connection *conn)
{
  int i;

  for(i = 0; i < MAX_ROWS; i++) {
    // make a prototype to initialize it
    struct Address addr = {.id = i, .set = 0};
    // then assign it
    conn->db->rows[i] = addr;
  }
}

void Database_set(struct Connection *conn, int id, const char *name, const char *email)
{
  struct Address *addr = &conn->db->rows[id];
  if(addr->set) die(conn, "Already set, delete it first");

  addr->set = 1;

  strncpy(addr->name, name, MAX_DATA);
  addr->name[MAX_DATA - 1]  = '\0';

  strncpy(addr->email, email, MAX_DATA);
  addr->email[MAX_DATA - 1]  = '\0';
}

void Database_get(struct Connection *conn, int id)
{
  struct Address *addr = &conn->db->rows[id];

  if(addr->set) {
    Address_print(addr);
  } else {
    die(conn, "ID is not set");
  }
}

void Database_find(struct Connection *conn, const char *name)
{
  int i;
  int found = 0;
  struct Database *db = conn->db;

  for(i = 0; i < MAX_ROWS; i++) {
    struct Address *addr = &db->rows[i];

    if(strcmp(addr->name, name) == 0) {
      Address_print(addr);
      found = 1;
      break;
    }
  }

  if(!found) {
    printf("%s was not found\n", name);
  }
}
開發者ID:tykowale,項目名稱:learningC,代碼行數:57,代碼來源:ex17.c

示例2: Database_create

void Database_create(struct Connection *conn)
{
	int i = 0;
	for(i = 0; i< MAX_ROWS; i++) {
		//make a prototype to initialize it
		struct Address addr= {.id=i, .set= 0};
		//then just assing it
		conn->db->rows[i] = addr;
	}
}


void Database_set(struct Connection *conn, int id, const char *name, const char *email)
{

	struct Address *addr = &conn->db->rows[id];
	if(addr->set) die("Already set, delete it first");

	addr->set = 1;
	//Warning: bug, read the "How to Break It" and fix this
	char *res = strncpy(addr->name, name, MAX_DATA);
	//demonstrate the strncpy bug
	if(!res) die("Name copy failed");

	res = strncpy(addr->email, email, MAX_DATA);
	if(!res) die("Email copy failed");
}

void Database_get(struct Connection *conn, int id)
{
	struct Address *addr = &conn->db->rows[id];

	if(addr->set){
		Address_print(addr);
	} else{
		die("ID is not set");
	}
}

void Database_find(struct Connection *conn, char *name)
{
	int i = 0;
	for (i = 0; i < MAX_ROWS; i++){
		struct Address *addr = &conn->db->rows[i];
		if (strcmp(addr->name, name) == 0){
			Address_print(addr);
			return;
		}
	}
	die("Record not found");
}			
開發者ID:caweinshenker,項目名稱:C_the_hard_way,代碼行數:51,代碼來源:ex17.c

示例3: serverFirstIncoming

static uint8_t serverFirstIncoming(struct Message* msg, struct Interface* iface)
{
    struct UDPInterfaceContext* uictx = (struct UDPInterfaceContext*) iface->receiverContext;

    struct Interface* udpDefault = UDPInterface_getDefaultInterface(uictx->udpContext);
    assert(udpDefault);
    UDPInterface_bindToCurrentEndpoint(udpDefault);

    struct User* u = CryptoAuth_getUser(iface);
    assert(u);
    // Add it to the switch, this will change the receiveMessage for this interface.
    struct Address addr;
    memset(&addr, 0, sizeof(struct Address));
    SwitchCore_addInterface(iface, u->trust, &addr.networkAddress_be, uictx->context->switchCore);

    uint8_t* herKey = CryptoAuth_getHerPublicKey(iface);
    memcpy(addr.key, herKey, 32);
    uint8_t printedAddr[60];
    Address_print(printedAddr, &addr);
    Log_info1(uictx->context->logger,
              "Node %s has connected to us.\n",
              printedAddr);

    // Prepare for the next connection.
    struct Interface* newUdpDefault = UDPInterface_getDefaultInterface(uictx->udpContext);
    struct Interface* newAuthedUdpDefault =
        CryptoAuth_wrapInterface(newUdpDefault, NULL, true, true, uictx->context->ca);
    newAuthedUdpDefault->receiveMessage = serverFirstIncoming;
    newAuthedUdpDefault->receiverContext = uictx;

    // Send the message on to the switch so the first message isn't lost.
    return iface->receiveMessage(msg, iface);
}
開發者ID:Ralith,項目名稱:cjdns,代碼行數:33,代碼來源:cjdroute.c

示例4: showActiveSearch

static void showActiveSearch(Dict* args, void* vctx, String* txid, struct Allocator* alloc)
{
    struct Context* ctx = Identity_check((struct Context*) vctx);
    int number = *(Dict_getIntC(args, "number"));

    struct SearchRunner_SearchData* search =
        SearchRunner_showActiveSearch(ctx->runner, number, alloc);

    Dict* dict = Dict_new(alloc);

    // Nothing is an error
    Dict_putString(dict, String_new("error", alloc), String_new("none", alloc), alloc);

    if (number < search->activeSearches) {
        uint8_t target[40];
        AddrTools_printIp(target, search->target);
        Dict_putString(dict, String_new("target", alloc), String_new((char*)target, alloc), alloc);

        uint8_t lastNodeAsked[60];
        Address_print(lastNodeAsked, &search->lastNodeAsked);
        Dict_putString(dict,
                       String_new("lastNodeAsked", alloc),
                       String_new((char*)lastNodeAsked, alloc),
                       alloc);

        Dict_putInt(dict, String_new("totalRequests", alloc), search->totalRequests, alloc);
    }
    Dict_putInt(dict, String_new("activeSearches", alloc), search->activeSearches, alloc);

    Admin_sendMessage(dict, txid, ctx->admin);
}
開發者ID:DmytroOrlov,項目名稱:cjdns,代碼行數:31,代碼來源:SearchRunner_admin.c

示例5: Keywords_find

void Keywords_find(struct Connection *connsrch, char **keywords, int counter)
{
    int rescntr = 0;                // counts findings
    struct Address *cur = connsrch->db->rows;
    int kwrd_index = counter + 2;   // gives the keyword index( 3 are the initial arguments of which we are totaly un-inderested so 2 their max index)
    int i;
        
    for( i = 0; i < counter; i++, kwrd_index--)
    {  
        printf("_Search term: \"%s\" \n",keywords[kwrd_index]);    	                  
        
        for(int j = 0; j < connsrch->db->MAX_ROWS; j++)
        {   
            if(cur[j].set)
            {
                if(Check_data(keywords[kwrd_index], &cur[j]))
                {
                    Address_print(&cur[j]);
                    rescntr++; 
                }
            }                              
        }
    }
    printf("\n	Search proccess returns %d result(s).\n\n", rescntr);
    printf("----------------------------------------------------------------------------------------------------------------------------------------\n");          
}
開發者ID:gifour,項目名稱:hello-world,代碼行數:26,代碼來源:addressbook_ex17.c

示例6: main

int main() {
    int max_rows = 10;
    int max_data = 10;

    printf("bananas\n");
    
    struct Database *db = malloc(sizeof(struct Database));
    db->rows = malloc(sizeof(struct Address) * max_rows);
    
    for (int i = 0; i < max_rows; i++) {
        struct Address addr = {.id=i, .set=1};
        addr.name = malloc(max_data);
        addr.email = malloc(max_data);
        db->rows[i] = addr;
    }
    
    struct Address *addr = &db->rows[2];
    strncpy(addr->name, "Bananas", max_data);

    for (int i = 0; i < max_rows; i++) {
        Address_print(&db->rows[i]);
    }
    

    for (int i = 0; i < max_rows; i++) {
        free(db->rows[i].name);
        free(db->rows[i].email);
    }
    free(db->rows);
    free(db);

    return 0;
}
開發者ID:pillserg,項目名稱:ctut,代碼行數:33,代碼來源:simp.c

示例7: Database_get

void Database_get(struct Connection *conn, int id) {
	struct Address *addr = &conn->db->rows[id];
	if (addr->set)
		Address_print(addr);
	else
		die("ID is not set.");
}
開發者ID:edek437,項目名稱:justcode,代碼行數:7,代碼來源:ex17noglob.c

示例8: RumorMill__addNode

void RumorMill__addNode(struct RumorMill* mill, struct Address* addr, const char* file, int line)
{
    struct RumorMill_pvt* rm = Identity_check((struct RumorMill_pvt*) mill);

    Address_getPrefix(addr);

    for (int i = 0; i < rm->pub.count; i++) {
        if (rm->pub.addresses[i].path == addr->path &&
                !Bits_memcmp(rm->pub.addresses[i].key, addr->key, 32))
        {
            return;
        }
    }

    if (!Bits_memcmp(addr->key, rm->selfAddr->key, 32)) {
        return;
    }

    struct Address* replace;
    if (rm->pub.count < rm->capacity) {
        replace = &rm->pub.addresses[rm->pub.count++];
    } else {
        replace = getWorst(rm);
    }
    Bits_memcpyConst(replace, addr, sizeof(struct Address));

    if (Defined(Log_DEBUG)) {
        uint8_t addrStr[60];
        Address_print(addrStr, addr);
        Log_debug(rm->log, "[%s] addNode(%s) count[%d] from [%s:%d]",
                  rm->pub.name, addrStr, rm->pub.count, file, line);
    }
}
開發者ID:cmotc,項目名稱:cjdns,代碼行數:33,代碼來源:RumorMill.c

示例9: incomingDHT

static inline uint8_t incomingDHT(struct Message* message,
                                  struct Address* addr,
                                  struct Ducttape_pvt* context)
{
    struct DHTMessage dht;
    Bits_memset(&dht, 0, sizeof(struct DHTMessage));

    // TODO: These copies are not necessary at all.
    const uint32_t length = (message->length < DHTMessage_MAX_SIZE)
        ? message->length
        : DHTMessage_MAX_SIZE;
    Bits_memcpy(dht.bytes, message->bytes, length);

    dht.address = addr;

    uint8_t buffer[PER_MESSAGE_BUF_SZ];
    dht.allocator = BufferAllocator_new(buffer, PER_MESSAGE_BUF_SZ);

    struct Jmp j;
    Jmp_try(j) {
        BufferAllocator_onOOM(dht.allocator, &j.handler);
        DHTModuleRegistry_handleIncoming(&dht, context->registry);
    } Jmp_catch {
        uint8_t printed[60];
        Address_print(printed, addr);
        Log_warn(context->logger, "Parsing message from [%s] failed; out of memory.", printed);
    }

    // TODO: return something meaningful.
    return Error_NONE;
}
開發者ID:wpapper,項目名稱:cjdns,代碼行數:31,代碼來源:Ducttape.c

示例10: lookup

static void lookup(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc)
{
    struct Context* ctx = vcontext;
    String* addrStr = Dict_getString(args, String_CONST("address"));
    char* err = NULL;
    uint8_t addr[16];
    uint8_t resultBuff[60];
    char* result = (char*) resultBuff;
    if (addrStr->len != 39) {
        err = "address wrong length";
    } else if (AddrTools_parseIp(addr, (uint8_t*) addrStr->bytes)) {
        err = "failed to parse address";
    } else {
        struct Node_Two* n = Router_lookup(ctx->router, addr);
        if (!n) {
            result = "not found";
        } else if (Bits_memcmp(addr, n->address.ip6.bytes, 16)) {
            Address_print(resultBuff, &n->address);
        } else {
            AddrTools_printPath(resultBuff, n->address.path);
        }
    }
    Dict response = Dict_CONST(
        String_CONST("error"), String_OBJ(String_CONST((err) ? err : "none")), Dict_CONST(
        String_CONST("result"), String_OBJ(String_CONST(result)), NULL
    ));
    Admin_sendMessage(&response, txid, ctx->admin);
}
開發者ID:0x20c24,項目名稱:cjdns,代碼行數:28,代碼來源:RouterModule_admin.c

示例11: Database_delete

/*
 * Zeros object at id. It's possible that create can just call this
 * as in it's for loop
 */
void Database_delete(struct Connection *conn, int id)
{
    //TODO this might need to change to deal with the new structure
    struct Address addr = {.id = id, .set = 0};
    conn->db->rows[id] = addr;
}

/*
 * Loop though the DB and if something is set print it
 */

void Database_list(struct Connection *conn)
{
    //TODO this might need to change to deal with the new structure
    int i = 0;
    struct Database *db = conn->db; //conn->db is a pointer to the DB

    for(i = 0; i < db->size; i++){
        //but db->rows[i] is an actual struct, hence the need for the &
        struct Address *cur = &db->rows[i]; 

        if (cur->set){
            Address_print(cur);
        }
    }
}
開發者ID:ssugrim,項目名稱:LCTHWex,代碼行數:30,代碼來源:ex17_ec.c

示例12: Database_get

void Database_get(Connection* c, int id) {
        Address* addr = &(c->db->rows[id]);

        if(addr->set) {
                Address_print(addr);
        } else {
                die(c,"Attempted `get` on unset entry");
        }
}
開發者ID:fosskers,項目名稱:playground,代碼行數:9,代碼來源:db.c

示例13: onPingResponse

static void onPingResponse(struct SwitchPinger_Response* resp, void* onResponseContext)
{
    if (SwitchPinger_Result_OK != resp->res) {
        return;
    }
    struct InterfaceController_Peer* ep =
        Identity_check((struct InterfaceController_Peer*) onResponseContext);
    struct InterfaceController_pvt* ic = ifcontrollerForPeer(ep);

    struct Address addr;
    Bits_memset(&addr, 0, sizeof(struct Address));
    Bits_memcpyConst(addr.key, CryptoAuth_getHerPublicKey(ep->cryptoAuthIf), 32);
    addr.path = ep->switchLabel;
    addr.protocolVersion = resp->version;

    #ifdef Log_DEBUG
        uint8_t addrStr[60];
        Address_print(addrStr, &addr);
        uint8_t key[56];
        Base32_encode(key, 56, CryptoAuth_getHerPublicKey(ep->cryptoAuthIf), 32);
    #endif

    if (!Version_isCompatible(Version_CURRENT_PROTOCOL, resp->version)) {
        Log_debug(ic->logger, "got switch pong from node [%s] with incompatible version [%d]",
                  key, resp->version);
    } else {
        Log_debug(ic->logger, "got switch pong from node [%s] with version [%d]",
                  key, resp->version);
    }

    if (!ep->timeOfLastPing) {
        // We've never heard from this machine before (or we've since forgotten about it)
        // This is here because we want the tests to function without the janitor present.
        // Other than that, it just makes a slightly more synchronous/guaranteed setup.
        Router_sendGetPeers(ic->router, &addr, 0, 0, ic->allocator);
    }

    struct Node_Link* link = Router_linkForPath(ic->router, resp->label);
    if (!link || !Node_getBestParent(link->child)) {
        RumorMill_addNode(ic->rumorMill, &addr);
    } else {
        Log_debug(ic->logger, "link exists");
    }

    ep->timeOfLastPing = Time_currentTimeMilliseconds(ic->eventBase);

    #ifdef Log_DEBUG
        // This will be false if it times out.
        //Assert_true(label == ep->switchLabel);
        uint8_t path[20];
        AddrTools_printPath(path, resp->label);
        uint8_t sl[20];
        AddrTools_printPath(sl, ep->switchLabel);
        Log_debug(ic->logger, "Received [%s] from lazy endpoint [%s]  [%s]",
                  SwitchPinger_resultString(resp->res)->bytes, path, sl);
    #endif
}
開發者ID:ValdekGreen,項目名稱:cjdns,代碼行數:57,代碼來源:InterfaceController.c

示例14: Database_get

void Database_get(int id)
{
    struct Address *addr = &conn->db->rows[id];

    if(addr->set) {
        Address_print(addr);
    } else {
        die("ID is not set");
    }
}
開發者ID:nebffa,項目名稱:lcthw,代碼行數:10,代碼來源:17.c

示例15: Database_get

void Database_get(struct Connection *conn, int id)
{
	struct Address *addr = conn->db->rows[id];

	if(addr->set) {
		Address_print(addr);
	} else {
		die("ID is not set", conn);
	}
}
開發者ID:osynetskyi,項目名稱:hardc,代碼行數:10,代碼來源:ex17.c


注:本文中的Address_print函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。