• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Address_print函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Address_print函数的典型用法代码示例。如果您正苦于以下问题:C++ Address_print函数的具体用法?C++ Address_print怎么用?C++ Address_print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Address_print函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Database_find

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);
		}
	}
}
开发者ID:paulogeyer,项目名称:lcthw,代码行数:10,代码来源:ex17.c


示例17: Database_get

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

    if(tmp->set) {
        Address_print(tmp);
    } else {
        die(conngt, "ID is not set");
    }
}
开发者ID:gifour,项目名称:hello-world,代码行数:10,代码来源:addressbook_ex17.c


示例18: Database_get

/*
 *Get basically prints the record
 */
void Database_get(struct Connection *conn, int id)
{
    //TODO this might need to change to deal with the new structure
    struct Address *addr = &conn->db->rows[id];

    if(addr->set){
        Address_print(addr);
    } else{
        die("ID is not set",conn);
    }
}
开发者ID:ssugrim,项目名称:LCTHWex,代码行数:14,代码来源:ex17_ec.c


示例19: Database_find

void Database_find(struct Connection *conn, char *term) {
int i = 0;
for (i = 0; i < conn->db->max_rows; i++) {
	struct Address *addr = &conn->db->rows[i];
	if (strcmp(addr->name, term) == 0 || strcmp(addr->email, term) == 0) {
		Address_print(addr);
		return;
	}
}
printf("No records matching '%s'\n", term);
}
开发者ID:edek437,项目名称:justcode,代码行数:11,代码来源:ex17noglob.c


示例20: Database_list

void Database_list()
{
    int i = 0;

    for(i = 0; i < max_rows; i++) {
        struct Address *cur = &conn->db->rows[i];
    
        if(cur->set) {
            Address_print(cur);
        }
    }
}
开发者ID:nebffa,项目名称:lcthw,代码行数:12,代码来源:17.c



注:本文中的Address_print函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ AdjustControlSize函数代码示例发布时间:2022-05-30
下一篇:
C++ AddressTableEntryLessThan函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap